#pragma once

#include "Event/EventEngine.h"
#include <QObject>
#include <QTimer>
#include <memory>
#include "TrSingleton.h"

namespace Market {

class TickStore;  // 前向声明

class MarketService : public QObject, public Common::TrSingleton<MarketService>
{
    Q_OBJECT
    friend class Common::TrSingleton<MarketService>;
public:
    bool init(const QString& configPath);
    void start();
    void stop();

private slots:
    void handleSyncFailed(const QString& error);
    void handleDailyTask();

private:
    void handleTick(const Event& event);
    void handleBar(const Event& event);
    void handleMarketConnected(const Event& event);
    void handleMarketDisconnected(const Event& event);

private:
    explicit MarketService(QObject *parent = nullptr);
    ~MarketService();

private:
    QString m_configPath;
    bool m_initialized{false};
    bool m_running{false};
    QTimer* m_dailyTimer{nullptr};
    std::unique_ptr<TickStore> m_tickStore;
};

} // namespace Market 